<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <title>优化样式3</title>
    <style>
    /*性别*/

    .sex span.warning {
        font-size: 1.4rem;
        color: #ccc;
    }

    .sex .male,
    .sex .female {
        position: relative;
        width: 4rem;
        height: 3.9rem;
        z-index: 1;
        line-height: 3.9rem;
        text-align: center;
    }

    .sex .male label,
    .sex .female label {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        width: 4rem;
        height: 3.9rem;
        z-index: 3;
        opacity: 0;
        margin: auto;
        display: inline-block;
        line-height: 3.9rem;
        cursor: pointer;
    }

    .sex input {
        display: inline-block;
        vertical-align: middle;
        /*让默认的单选样式的圆圈和“男”“女”的文本没有高差，看起来在同一水平线*/
        height: 2.8rem;
        line-height: 2.8rem;
        margin: 0;
        /*清除浏览器默认的外边距*/
    }

    .sex .male span.btn,
    .sex .female span.btn {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        width: 4rem;
        height: 2.8rem;
        z-index: 2;
        margin: auto;
        display: inline-block;
        line-height: 2.6rem;
        text-align: center;
        border: .1rem solid #fe5454;
        color: #fe5454;
    }

    .sex .male span {
        border-top-left-radius: .2rem;
        border-bottom-left-radius: .2rem;
    }

    .sex .female span {
        border-top-right-radius: .2rem;
        border-bottom-right-radius: .2rem;
    }

    .sex .male span.active,
    .sex .female span.active {
        background-color: #fe5454;
        color: #fff;
    }
    </style>
</head>

<body>
    <div class="sex">
        <span class="warning fl">性别确定后将不可更改！</span>
        <div class="select fr">
            <div class="male fl">
                <label for="male">
                    <input type="radio" name="sex" id="male" checked>男
                </label>
                <span class="btn active">男</span>
            </div>
            <div class="female fl">
                <label for="female">
                    <input type="radio" name="sex" id="female">女
                </label>
                <span class="btn">女</span>
            </div>
        </div>
    </div>
    <script src="../js/jquery-2.1.0.min.js"></script>
    <script>
    $(function() {
        $(".select label").click(function() {
            $(this).siblings("span").addClass("active");
            $(this).parent().siblings("div").find("span").removeClass("active");
        });
    })
    </script>
</body>

</html>